<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta name="exporter-version" content="Evernote Mac 9.4.6 (461470)"/><meta name="altitude" content="6.751529216766357"/><meta name="author" content="704206198@qq.com"/><meta name="created" content="2020-08-15 14:18:00 +0000"/><meta name="latitude" content="31.37538146972656"/><meta name="longitude" content="121.4935242188129"/><meta name="source" content="desktop.mac"/><meta name="updated" content="2021-01-31 14:27:14 +0000"/><meta name="content-class" content="yinxiang.markdown"/><title>拓展：YARN</title></head><body><div style="font-size: 14px; margin: 0; padding: 0; width: 100%;"><h1 style="line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 41px; border-bottom: 3px double #999; color: #000; margin-top: 14px;">一、下载</h1>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">快速，可靠和安全的依赖关系管理。</p>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;"><a href="https://classic.yarnpkg.com/" style="line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;">yarn官网</a></p>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;"><a href="https://classic.yarnpkg.com/en/docs/install#mac-stable" style="line-height: 160%; box-sizing: content-box; text-decoration: underline; color: #5286bc;">下载地址</a></p>
<blockquote style="line-height: 160%; box-sizing: content-box; margin: 15px 0; border-left: 4px solid #ddd; padding: 0 15px; color: #777;">
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333; margin-top: 0; margin-bottom: 0;">注意：为省事，不要用npm i yarn -g，去安装yarn，而是去下载压缩包，保证注册表和环境变量的硬写入，后期通过yarn安装全局包时方便</p>
</blockquote>
<h1 style="line-height: 160%; box-sizing: content-box; font-weight: 700; font-size: 41px; border-bottom: 3px double #999; color: #000;">二、使用</h1>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">初始化一个新项目</strong></p>
<pre style="line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;"><code style="display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;">yarn init
</code></pre>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">添加依赖包</strong></p>
<pre style="line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;"><code style="display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;">yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]
</code></pre>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">将依赖项添加到不同依赖项类别中</strong></p>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">分别添加到 <code style="line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;">dependencies</code>,<code style="line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;">devDependencies</code>、<code style="line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;">peerDependencies</code> 和 <code style="line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; color: #c1788b; padding: 4px 4px 2px 0; letter-spacing: -.3px;">optionalDependencies</code> 类别中：</p>
<pre style="line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;"><code style="display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;">yarn add [package] --save   | -S 
yarn add [package] --dev    | -D 
yarn add [package] --peer
yarn add [package] --optional
</code></pre>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">升级依赖包</strong></p>
<pre style="line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;"><code style="display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;">yarn upgrade [package]
yarn upgrade [package]@[version]
yarn upgrade [package]@[tag]
</code></pre>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">移除依赖包</strong></p>
<pre style="line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;"><code style="display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;">yarn remove [package]
</code></pre>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">安装项目的全部依赖</strong></p>
<pre style="line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;"><code style="display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;">yarn
</code></pre>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;">或者</p>
<pre style="line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;"><code style="display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;">yarn install
</code></pre>
<p style="line-height: 160%; box-sizing: content-box; margin: 10px 0; color: #333;"><strong style="line-height: 160%; box-sizing: content-box; font-weight: 700;">安装到全局</strong></p>
<pre style="line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; margin: 2px 0 8px; background-color: #f5f7f8;"><code style="display: block; overflow-x: auto; background: #1e1e1e; line-height: 160%; box-sizing: content-box; border: 0; border-radius: 0; letter-spacing: -.3px; padding: 18px; color: #f4f4f4; white-space: pre-wrap;">yarn global add [package]				<span style="color: #57a64a; font-style: italic; line-height: 160%; box-sizing: content-box;">//global的位置测试不能变</span>
yarn global remove [package]
</code></pre>
</div><center style="display:none !important;visibility:collapse !important;height:0 !important;white-space:nowrap;width:100%;overflow:hidden">%23%20%E4%B8%80%E3%80%81%E4%B8%8B%E8%BD%BD%0A%E5%BF%AB%E9%80%9F%EF%BC%8C%E5%8F%AF%E9%9D%A0%E5%92%8C%E5%AE%89%E5%85%A8%E7%9A%84%E4%BE%9D%E8%B5%96%E5%85%B3%E7%B3%BB%E7%AE%A1%E7%90%86%E3%80%82%0A%5Byarn%E5%AE%98%E7%BD%91%5D(https%3A%2F%2Fclassic.yarnpkg.com%2F)%0A%0A%5B%E4%B8%8B%E8%BD%BD%E5%9C%B0%E5%9D%80%5D(https%3A%2F%2Fclassic.yarnpkg.com%2Fen%2Fdocs%2Finstall%23mac-stable)%0A%0A%3E%20%E6%B3%A8%E6%84%8F%EF%BC%9A%E4%B8%BA%E7%9C%81%E4%BA%8B%EF%BC%8C%E4%B8%8D%E8%A6%81%E7%94%A8npm%20i%20yarn%20-g%EF%BC%8C%E5%8E%BB%E5%AE%89%E8%A3%85yarn%EF%BC%8C%E8%80%8C%E6%98%AF%E5%8E%BB%E4%B8%8B%E8%BD%BD%E5%8E%8B%E7%BC%A9%E5%8C%85%EF%BC%8C%E4%BF%9D%E8%AF%81%E6%B3%A8%E5%86%8C%E8%A1%A8%E5%92%8C%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E7%9A%84%E7%A1%AC%E5%86%99%E5%85%A5%EF%BC%8C%E5%90%8E%E6%9C%9F%E9%80%9A%E8%BF%87yarn%E5%AE%89%E8%A3%85%E5%85%A8%E5%B1%80%E5%8C%85%E6%97%B6%E6%96%B9%E4%BE%BF%0A%0A%23%20%E4%BA%8C%E3%80%81%E4%BD%BF%E7%94%A8%0A%0A**%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%80%E4%B8%AA%E6%96%B0%E9%A1%B9%E7%9B%AE**%0A%0A%60%60%60%0Ayarn%20init%0A%60%60%60%0A%0A**%E6%B7%BB%E5%8A%A0%E4%BE%9D%E8%B5%96%E5%8C%85**%0A%0A%60%60%60%0Ayarn%20add%20%5Bpackage%5D%0Ayarn%20add%20%5Bpackage%5D%40%5Bversion%5D%0Ayarn%20add%20%5Bpackage%5D%40%5Btag%5D%0A%60%60%60%0A%0A**%E5%B0%86%E4%BE%9D%E8%B5%96%E9%A1%B9%E6%B7%BB%E5%8A%A0%E5%88%B0%E4%B8%8D%E5%90%8C%E4%BE%9D%E8%B5%96%E9%A1%B9%E7%B1%BB%E5%88%AB%E4%B8%AD**%0A%0A%E5%88%86%E5%88%AB%E6%B7%BB%E5%8A%A0%E5%88%B0%20%60%60dependencies%60%60%2C%60devDependencies%60%E3%80%81%60peerDependencies%60%20%E5%92%8C%20%60optionalDependencies%60%20%E7%B1%BB%E5%88%AB%E4%B8%AD%EF%BC%9A%0A%0A%60%60%60%0Ayarn%20add%20%5Bpackage%5D%20--save%20%20%20%7C%20-S%20%0Ayarn%20add%20%5Bpackage%5D%20--dev%20%20%20%20%7C%20-D%20%0Ayarn%20add%20%5Bpackage%5D%20--peer%0Ayarn%20add%20%5Bpackage%5D%20--optional%0A%60%60%60%0A%0A**%E5%8D%87%E7%BA%A7%E4%BE%9D%E8%B5%96%E5%8C%85**%0A%0A%60%60%60%0Ayarn%20upgrade%20%5Bpackage%5D%0Ayarn%20upgrade%20%5Bpackage%5D%40%5Bversion%5D%0Ayarn%20upgrade%20%5Bpackage%5D%40%5Btag%5D%0A%60%60%60%0A%0A**%E7%A7%BB%E9%99%A4%E4%BE%9D%E8%B5%96%E5%8C%85**%0A%0A%60%60%60%0Ayarn%20remove%20%5Bpackage%5D%0A%60%60%60%0A%0A**%E5%AE%89%E8%A3%85%E9%A1%B9%E7%9B%AE%E7%9A%84%E5%85%A8%E9%83%A8%E4%BE%9D%E8%B5%96**%0A%0A%60%60%60%0Ayarn%0A%60%60%60%0A%0A%E6%88%96%E8%80%85%0A%0A%60%60%60%0Ayarn%20install%0A%60%60%60%0A%0A**%E5%AE%89%E8%A3%85%E5%88%B0%E5%85%A8%E5%B1%80**%0A%0A%60%60%60js%0Ayarn%20global%20add%20%5Bpackage%5D%09%09%09%09%2F%2Fglobal%E7%9A%84%E4%BD%8D%E7%BD%AE%E6%B5%8B%E8%AF%95%E4%B8%8D%E8%83%BD%E5%8F%98%0Ayarn%20global%20remove%20%5Bpackage%5D%0A%60%60%60%0A%0A%0A%0A%0A%0A%0A</center></body></html>